import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(Router)

const router = new Router({
  mode: "history",
  linkActiveClass: "active",
  routes: [{
      path: '/',
      redirect: '/index',
      meta: {
        keepAlive: false
      }
    }, {
      path: "/",
      name: "Home",
      component: Home,
      children: [{
          path: "/dashboard",
          name: "dashboard",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/Dashboard.vue"),
          meta: {
            keepAlive: true,
            title: '数据管理中心'
          }
        },
        {
          path: "/activity",
          name: "activity",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Activity.vue"),
          meta: {
            keepAlive: true,
            title: '参加的活动'
          }
        },
        {
          path: "/activity_order",
          name: "order",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Activity_order.vue"),
          meta: {
            keepAlive: true,
            title: '我的活动订单'
          }
        },
        {
          path: "/group",
          name: "group",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Group.vue"),
          meta: {
            keepAlive: true,
            title: '我参加的团队'
          }
        },
        {
          path: "/group_sq",
          name: "group_sq",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Group_sq.vue"),
          meta: {
            keepAlive: true,
            title: '我申请的团队'
          }
        },
        {
          path: "/manage",
          name: "manage",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Manage.vue"),
          meta: {
            keepAlive: true,
            title: '管理的团队'
          }
        },
        {
          path: "/releasemanage",
          name: "releasemanage",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Release_manage.vue"),
          meta: {
            keepAlive: true,
            title: '管理的团队-活动管理'
          }
        },
        {
          path: "/activemanage",
          name: "activemanage",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Active_manage.vue"),
          meta: {
            keepAlive: true,
            title: '活动管理'
          }
        },
        {
          path: "/activeinformation",
          name: "activeinformation",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/participate/Active_information.vue"),
          meta: {
            keepAlive: true,
            title: '管理的团体-消息'
          }
        },
        {
          path: "/my_activities",
          name: "my_activities",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/my_activities.vue"),
          meta: {
            keepAlive: true,
            title: '我的活动'
          }
        },
        {
          path: "/activedetail",
          name: "activedetail",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/Activedetail.vue"),
          meta: {
            keepAlive: true,
            title: '我的活动'
          }
        },
        {
          path: "/details",
          name: "details",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/Details.vue"),
          meta: {
            keepAlive: true,
            title: '基本信息'
          }
        },
        {
          path: "/release",
          name: "release",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/Release.vue"),
          meta: {
            keepAlive: true,
            title: '发布活动'
          }
        },
        {
          path: "/release_edit",
          name: "release_edit",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/Release_edit.vue"),
          meta: {
            keepAlive: true,
            title: '管理活动'
          }
        },
        {
          path: "/teamdetail",
          name: "teamdetail",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/Detail.vue"),
          meta: {
            keepAlive: true,
            title: '团队详情'
          }
        },
        {
          path: "/create",
          name: "create",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/Create.vue"),
          meta: {
            keepAlive: true,
            title: '创建团队'
          }
        },
        {
          path: "/team_edit",
          name: "team_edit",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/Create.vue"),
          meta: {
            keepAlive: true,
            title: '修改团队'
          }
        },
        {
          path: "/my_group",
          name: "my_group",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/My_group.vue"),
          meta: {
            keepAlive: true,
            title: '我的团队'
          }
        },
        {
          path: "/apply",
          name: "apply",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/Apply.vue"),
          meta: {
            keepAlive: true,
            title: '成员申请'
          }
        },
        {
          path: "/group_details",
          name: "group_details",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/group/Group_details.vue"),
          meta: {
            keepAlive: true,
            title: '我的团队'
          }
        },
        {
          path: "/activities_detail",
          name: "activities_detail",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/my_activities/activities_detail.vue"),
          meta: {
            keepAlive: true,
            title: '管理的团队'
          }
        },
        {
          path: "/write_story",
          name: "write_story",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/story/Write_story.vue"),
          meta: {
            keepAlive: true,
            title: '写故事'
          }
        },
        {
          path: "/my_story",
          name: "my_story",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/story/my_story.vue"),
          meta: {
            keepAlive: true,
            title: '我的故事'
          }
        },
        {
          path: "/collect",
          name: "collect",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/collect/collect.vue"),
          meta: {
            keepAlive: true,
            title: '收藏的活动'
          }
        },
        {
          path: "/collect_team",
          name: "collect_team",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/collect/collect_team.vue"),
          meta: {
            keepAlive: true,
            title: '收藏的团队'
          }
        },
        {
          path: "/footprint",
          name: "footprint",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/footprint/Footprint.vue"),
          meta: {
            keepAlive: true,
            title: '我的足迹'
          }
        },
        {
          path: "/information",
          name: "information",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/information/information.vue"),
          meta: {
            keepAlive: true,
            title: '未读消息'
          }
        },
        {
          path: "/information_y",
          name: "information_y",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/information/information_y.vue"),
          meta: {
            keepAlive: true,
            title: '已读消息'
          }
        },
        {
          path: "/information_details",
          name: "information_details",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/information/information_details.vue"),
          meta: {
            keepAlive: true,
            title: '系统消息'
          }
        },
        {
          path: "/finance",
          name: "finance",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/finance/finance.vue"),
          meta: {
            keepAlive: true,
            title: '财务中心'
          }
        },
        {
          path: "/finance_bank",
          name: "finance_bank",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/finance/finance_bank.vue"),
          meta: {
            keepAlive: true,
            title: '收款账号'
          }
        },
        {
          path: "/finance_out",
          name: "finance_out",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/finance/finance_out.vue"),
          meta: {
            keepAlive: true,
            title: '提现记录'
          }
        },
        {
          path: "/finance_list",
          name: "finance_list",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/finance/finance_list.vue"),
          meta: {
            keepAlive: true,
            title: '收款明细'
          }
        },
        {
          path: "/personal",
          name: "personal",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/My_account/personal.vue"),
          meta: {
            keepAlive: true,
            title: '个人资料'
          }
        },
        {
          path: "/password",
          name: "password",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/My_account/password.vue"),
          meta: {
            keepAlive: true,
            title: '修改密码'
          }
        },
        {
          path: "/verified",
          name: "verified",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/My_account/Verified.vue"),
          meta: {
            keepAlive: true,
            title: '实名认证'
          }
        },
        {
          path: "/login",
          name: "login",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/login.vue"),
          meta: {
            title: '登录',
            keepAlive: false
          }
        },
        {
          path: "/dx_login",
          name: "dx_login",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/dx_login.vue"),
          meta: {
            title: '短信登录',
            keepAlive: false
          }
        },
        {
          path: "/register",
          name: "register",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/register.vue"),
          meta: {
            title: '手机注册',
            keepAlive: false
          }
        },
        {
          path: "/emilaregsiter",
          name: "emilaregsiter",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/emilaregsiter.vue"),
          meta: {
            title: '邮箱注册',
            keepAlive: false
          }
        },
        {
          path: "/forgetpas",
          name: "forgetpas",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/forger_pas.vue"),
          meta: {
            title: '手机号找回密码',
            keepAlive: false
          }
        },
        {
          path: "/forgetemailepas",
          name: "forgetemailepas",
          component: () => import( /* webpackChunkName: "dashboard" */ "../views/login/forgetemailepas.vue"),
          meta: {
            title: '邮箱找回密码',
            keepAlive: false
          }
        },
      ]
    },
    {
      path: "/index",
      name: "index",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/index.vue"),
      meta: {
        title: '',
        keepAlive: false
      }
    }, {
      path: "/hotlist",
      name: "hotlist",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/hotactive/list.vue"),
      meta: {
        title: '热门活动',
        keepAlive: false
      }
    },
    {
      path: "/hotshow",
      name: "hotshow",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/hotactive/show.vue"),
      meta: {
        title: '热门活动详情',
        keepAlive: false
      }
    },
    {
      path: "/hotteamlist",
      name: "hotteamlist",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/hotteam/list.vue"),
      meta: {
        title: '热门团队',
        keepAlive: false
      }
    },


    {
      path: "/hotteamshow/:id",
      name: "hotteamshow",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/hotteam/show.vue"),
      meta: {
        title: '热门团队详情',
        keepAlive: false
      }
    },
    {
      path: "/stroylist",
      name: "stroylist",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/ourstory/list.vue"),
      meta: {
        title: '我们的故事',
        keepAlive: false
      }
    },
    {
      path: "/stroyshow",
      name: "stroyshow",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/ourstory/show.vue"),
      meta: {
        title: '我们的故事详情',
        keepAlive: false
      }
    },
    {
      path: "/newslist",
      name: "newslist",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/news/list.vue"),
      meta: {
        title: '新闻',
        keepAlive: false
      }
    },
    {
      path: "/newsshow",
      name: "newsshow",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/news/show.vue"),
      meta: {
        title: '新闻详情',
        keepAlive: false
      }
    },
    {
      path: "/qa",
      name: "qa",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/qa.vue"),
      meta: {
        title: '常见问题',
        keepAlive: false
      }
    },
    {
      path: "/bidu",
      name: "bidu",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/bidu.vue"),
      meta: {
        title: '必读',
        keepAlive: false
      }
    },
    {
      path: "/help",
      name: "help",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/help.vue"),
      meta: {
        title: '帮助中心',
        keepAlive: false
      }
    },
    {
      path: "/aboutus",
      name: "aboutus",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/aboutus.vue"),
      meta: {
        title: '关于我们',
        keepAlive: false
      }
    },
    {
      path: "/success",
      name: "success",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/success.vue"),
      meta: {
        title: '报名成功',
        keepAlive: false
      }
    },
    {
      path: "/joinsuccess",
      name: "joinsuccess",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/joinsuccess.vue"),
      meta: {
        title: '加入成功',
        keepAlive: false
      }
    },
    {
      path: "/contact",
      name: "contact",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/contact.vue"),
      meta: {
        title: '联系我们',
        keepAlive: false
      }
    },
    {
      path: "/zhifu",
      name: "zhifu",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/zhifu.vue"),
      meta: {
        title: '支付',
        keepAlive: false
      }
    },
    {
      path: "/yhzcxy",
      name: "yhzcxy",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/yhzcxy.vue"),
      meta: {
        title: 'Jujuamici用户注册协议',
        keepAlive: false
      }
    },
    {
      path: "/reportcenter",
      name: "reportcenter",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/reportcenter.vue"),
      meta: {
        title: '举报中心',
        keepAlive: false
      }
    },
    {
      path: "/useragreement",
      name: "useragreement",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/useragreement.vue"),
      meta: {
        title: '用户协议',
        keepAlive: false
      }
    },
    {
      path: "/eventrelease",
      name: "eventrelease",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/eventrelease.vue"),
      meta: {
        title: '活动发布',
        keepAlive: false
      }
    },
    {
      path: "/eventmanagement",
      name: "eventmanagement",
      component: () => import( /* webpackChunkName: "dashboard" */ "../website/about/eventmanagement.vue"),
      meta: {
        title: '活动管理',
        keepAlive: false
      }
    },
  ]
});


// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title + '-聚聚阿米奇';
  }

  //为true时，要验证是否登陆
  if (to.meta.keepAlive) {
    let token = window.localStorage.getItem('token');
    //console.log('token', token);
    if (token === null || token === '') {
      next('/login');
    } else {
      next();
    }
  } else {
    next();
  }
});

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router;
